// scaup - Scala up!
// (c) 2009-2010, Normen Müller, normen.mueller@gmail.com  
// $Id: GM.scala 94 2010-06-12 15:35:36Z normen.mueller $
package locutor.rws.gm.parsing

import java.io.File

import scaup.Views._

/** This object provides a simple interface to the graph model parser class.
 * 
 *  @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 *  @version 0.0.5
 */
private [locutor] object GraphModelParser extends Parser {
  def parse(description: File): GraphModel =
    if(description == null)
      error("Graph model description may not be null.")
    else if(! (description exists))
      error("Graph model description \"" + description.path + "\" does not exists.")
    else parse(description.content)
    
  def parse(description: String) = phrase(gm)(new lexical.Scanner(description)) match {
    case Success(result, _) => result
    case n@_                => throw new Exception("GM parsing error: " + n)
  }  
}
